package com.djakapm.swing.component.tab;

import com.djakapm.swing.common.ContainerFactory;

import javax.swing.*;
import java.awt.event.ActionEvent;

public class SpecForTab {


    public void can_execute_an_action_after_close_a_tab_header(){
        JFrame frame = ContainerFactory.newFrame("Can execute an action after tab close");
        Tab tab = new Tab();
        tab.setAfterTabCloseAction(new AbstractAction(){

            public void actionPerformed(ActionEvent e) {
                System.out.println("after tab close do something.");
            }
        });
        tab.setClosable(true);
        tab.add("Test1",new JButton("Button1"));
        tab.add("Test2",new JButton("Button2"));
        frame.getContentPane().add(tab);
        frame.setVisible(true);
    }

    public void can_show_closable_tab_header(){
        JFrame frame = ContainerFactory.newFrame("Should show closable tabs");
        Tab tab = new Tab();
        tab.setClosable(true);
        tab.add("Test1",new JButton("Button1"));
        tab.add("Test2",new JButton("Button2"));
        frame.getContentPane().add(tab);
        frame.setVisible(true);
    }

    public void can_show_regular_tab_header(){
        JFrame frame = ContainerFactory.newFrame("Should show regular tabs");
        Tab tab = new Tab();
        tab.add("Test1",new JButton("Button1"));
        tab.add("Test2",new JButton("Button2"));
        frame.getContentPane().add(tab);
        frame.setVisible(true);
    }

    public void can_set_default_close_operation_to_false(){
        JFrame frame = ContainerFactory.newFrame("Set default close operation to false");
        final Tab tab = new Tab();
        tab.setDefaultCloseOperation(false);
        tab.setClosable(true);
        JButton button1 = new JButton("Button1");
        button1.setAction(
                new AbstractAction(){
                    public void actionPerformed(ActionEvent e) {
                        tab.removeTabAt(1);
                    }
                }
        );

        tab.add("Test1",button1);
        tab.add("Test2",new JButton("Button2"));
        frame.getContentPane().add(tab);
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        SpecForTab sft = new SpecForTab();
        sft.can_show_closable_tab_header();
        sft.can_show_regular_tab_header();
        sft.can_execute_an_action_after_close_a_tab_header();
        sft.can_set_default_close_operation_to_false();
    }
}